package com.king.tv.mvp.activity;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jaeger.library.StatusBarUtil;
import com.king.tv.R;
import com.king.tv.bean.LiveImageList;
import com.king.tv.dao.greendao.bean.contactus;
import com.king.tv.http.BaseCallModel;
import com.king.tv.http.HttpLoader;
import com.king.tv.mvp.base.PureActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ContactActivity extends PureActivity {


    @BindView(R.id.tvtoqq)
    TextView tvtoqq;
    @BindView(R.id.tvtowx)
    TextView tvtowx;
    @BindView(R.id.ivLeft)
    ImageView ivLeft;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.ivRight)
    ImageView ivRight;

    @Override
    public int getRootViewId() {
        return R.layout.activity_contactus;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void initUI() {
        StatusBarUtil.setColor(ContactActivity.this, getResources().getColor(R.color.colorPrimaryDark));

        tvtoqq.setText("qq:");
        tvtowx.setText("微信:");
        tvTitle.setText("联系我们");
        ivLeft.setImageResource(R.drawable.ic_zhibojian_shu_back_pressed);
        ivRight.setVisibility(View.GONE);
        HttpLoader.getInstance().getService().subscribe(new Observer<Object>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                Log.i("tag", "=============abcd" + value);
                Gson gson = new Gson();
                String result = gson.toJson(value);
                BaseCallModel baseCallModel = gson.fromJson(result,BaseCallModel.class);
                Log.i("tag", "=============abcd" + baseCallModel.getData().toString());
                if(baseCallModel.getData()!=null){
                    String json1 = gson.toJson(baseCallModel.getData());
                    Log.i("tag", "=============abcd" + json1);
                    List<contactus> us = gson.fromJson(json1,new TypeToken<List<contactus>>(){}.getType());
                    if(us.size()>0){
                    tvtoqq.setText("  QQ:"+us.get(0).getContent());
                    tvtowx.setText( "微信:"+us.get(1).getContent());
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.i("tag", "=============abcd" + e);
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.ivLeft, R.id.tvtoqq, R.id.tvtowx})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivLeft:
                finish();
                break;
            case R.id.tvtoqq:
                break;
            case R.id.tvtowx:
                break;
        }
    }
}
